/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package id3.UIs;

import id3.utils.RandomData;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author NguyenVan
 */
public class RandomPanel extends javax.swing.JPanel {

    /**
     * Creates new form RandomPanel
     */
    public RandomPanel() {
        initComponents();
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        fileData = new javax.swing.JFileChooser();
        jLabel1 = new javax.swing.JLabel();
        txtData = new javax.swing.JTextField();
        btnDataFile = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtTraining = new javax.swing.JTextField();
        btnTrainingFile = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        txtTest = new javax.swing.JTextField();
        btnTestFile = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        lblResult = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        _TrainingRate = new javax.swing.JComboBox();

        fileData.setApproveButtonText("");
        fileData.setApproveButtonToolTipText("");

        setEnabled(false);
        setLayout(new java.awt.GridBagLayout());

        jLabel1.setText("File data :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.25;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(jLabel1, gridBagConstraints);

        txtData.setEditable(false);
        txtData.setColumns(20);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.5;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(txtData, gridBagConstraints);

        btnDataFile.setText("Chọn file data");
        btnDataFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDataFileActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.25;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(btnDataFile, gridBagConstraints);

        jLabel2.setText("File Training : ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.25;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(jLabel2, gridBagConstraints);

        txtTraining.setEditable(false);
        txtTraining.setColumns(20);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.5;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(txtTraining, gridBagConstraints);

        btnTrainingFile.setText("Chọn vị trí file training");
        btnTrainingFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTrainingFileActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.25;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(btnTrainingFile, gridBagConstraints);

        jLabel3.setText("File test :");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.25;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(jLabel3, gridBagConstraints);

        txtTest.setEditable(false);
        txtTest.setColumns(20);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.5;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(txtTest, gridBagConstraints);

        btnTestFile.setText("Chọn file test");
        btnTestFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTestFileActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.25;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(btnTestFile, gridBagConstraints);

        jButton4.setText("Tạo ngẫu nhiên data");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(jButton4, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.weightx = 0.25;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(lblResult, gridBagConstraints);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Tỉ lệ Training/Test:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.25;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(jLabel4, gridBagConstraints);

        _TrainingRate.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tỉ lệ 6:4", "Tỉ lệ 7:3", "Tỉ lệ 8:2" }));
        _TrainingRate.setActionCommand("");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.5;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(_TrainingRate, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void btnTrainingFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTrainingFileActionPerformed
        fileData.setCurrentDirectory(new File(System.getProperty("user.dir")));
        int input = fileData.showSaveDialog(this);
        if (input == JFileChooser.APPROVE_OPTION) {
            txtTraining.setText(fileData.getSelectedFile().getPath());
        }
    }//GEN-LAST:event_btnTrainingFileActionPerformed

    private void btnDataFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDataFileActionPerformed
        fileData.setCurrentDirectory(new File(System.getProperty("user.dir")));
        int input = fileData.showOpenDialog(this);
        if (input == JFileChooser.APPROVE_OPTION) {
            txtData.setText(fileData.getSelectedFile().getPath());
        }
    }//GEN-LAST:event_btnDataFileActionPerformed

    private void btnTestFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTestFileActionPerformed
        fileData.setCurrentDirectory(new File(System.getProperty("user.dir")));
        int input = fileData.showSaveDialog(this);
        if (input == JFileChooser.APPROVE_OPTION) {
            txtTest.setText(fileData.getSelectedFile().getPath());
        }
    }//GEN-LAST:event_btnTestFileActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        RandomData data = new RandomData();
        int index= _TrainingRate.getSelectedIndex();
        int rate=6;
        if(index==1){
            rate=7;
        }else if(index==2){
            rate=8;
        }
        if (data.randomData(txtData.getText(), txtTraining.getText(), txtTest.getText(),rate)) {
            JOptionPane.showMessageDialog(this, "Xong !", "Xong !", JOptionPane.PLAIN_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(this, "Loi !", "Xong !", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox _TrainingRate;
    private javax.swing.JButton btnDataFile;
    private javax.swing.JButton btnTestFile;
    private javax.swing.JButton btnTrainingFile;
    private javax.swing.JFileChooser fileData;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel lblResult;
    private javax.swing.JTextField txtData;
    private javax.swing.JTextField txtTest;
    private javax.swing.JTextField txtTraining;
    // End of variables declaration//GEN-END:variables
}
